package com.share.bigdata.hdfs.conf;

import org.apache.hadoop.fs.FileSystem;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.URI;

@Configuration
public class HdfsConf {

    @Value("${hdfs.uri}")
    private String hdfsUri;

    @Value("${hdfs.username}")
    private String username;

    @Value("${hdfs.password}")
    private String password;

    @Bean
    public FileSystem init() throws Exception {
        // 获取配置对象
        org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
        FileSystem fileSystem = FileSystem.get(new URI(hdfsUri), conf, username);
        return fileSystem;
    }
}
